package com.liangwj.springbootdesignpatterns.structureTypePatterns.composite.demo_2;

import java.math.BigDecimal;

public class CompositeDemo2Test {

    public static void main(String[] args) {
        //CEO
        ConcreateCompany ceo = new ConcreateCompany("liangwj", "male", "ceo", new BigDecimal(20000));

        //三个经理
        ConcreateCompany developDept = new ConcreateCompany("阿萨德", "男", "技术主管", new BigDecimal(15000));
        ConcreateCompany salesDept = new ConcreateCompany("理查德", "男", "销售主管", new BigDecimal(10000));
        ConcreateCompany finaceDept = new ConcreateCompany("玛丽", "女", "财务主管", new BigDecimal(15000));
        ceo.add(developDept);
        ceo.add(salesDept);
        ceo.add(finaceDept);

        //部门员工
        Employee emp0 = new Employee("A", "男", "技术部", new BigDecimal(12000));
        Employee emp1 = new Employee("B", "女", "技术部", new BigDecimal(11000));
        Employee emp2 = new Employee("C", "男", "技术部", new BigDecimal(10000));
        developDept.add(emp0);
        developDept.add(emp1);
        developDept.add(emp2);

        Employee emp3 = new Employee("D", "女", "销售部", new BigDecimal(7000));
        Employee emp4 = new Employee("E", "女", "销售部", new BigDecimal(8000));
        Employee emp5 = new Employee("F", "男", "销售部", new BigDecimal(6000));
        salesDept.add(emp3);
        salesDept.add(emp4);
        salesDept.add(emp5);

        Employee emp6 = new Employee("G", "男", "财务部", new BigDecimal(12000));
        Employee emp7 = new Employee("H", "男", "财务部", new BigDecimal(8000));
        Employee emp8 = new Employee("I", "女", "财务部", new BigDecimal(8000));
        finaceDept.add(emp6);
        finaceDept.add(emp7);
        finaceDept.add(emp8);

        //打印公司人员架构
        System.out.println(ceo.getInfo());
        //多层级节点输出 需要迭代
        display(ceo);


    }

    private static void display(ConcreateCompany node) {
        for (Company company : node.getChild()) {
            if (company instanceof Employee) { //节点类型是叶子节点(就是没有下一级节点了)
                System.out.println(company.getInfo());
            } else { //树枝节点
                System.out.println("\n" + company.getInfo());
                display((ConcreateCompany) company);
            }
        }
    }
}
